import sys
sys.path.append("../")
from frameworks.cores.LoadClass import *
from services.CodesService import *
from controller.ScoreCalcController import *
from services.DayKlineService import *
from frameworks.utils.FileUtil import *

class ParseScoreStockController:
    def __init__(self):
        self.load = LoadClass()
        self.codeService = CodeService()
        self.score = ScoreCalcController()
        self.klineService = DayKlineService()

    def multirun(self, args={}):
        codes = self.codeService.getDivCodeData(str(args["id"]))
        for codeinfo in codes:
            self.pushStockData(codeinfo,args)

    def pushStockData(self,codeinfo,args):
        score, zf, money_score, money_zf = self.score.calcScore(codeinfo["code"], args["startDay"], args["endDay"])
        result = self.klineService.getDataByDate(codeinfo["code"], args["resultDay"], args["resultDay"])
        if result == "" or result == None or result == False or len(result) < 1:
            return ""
        close = float(result[0]["close"])
        if result[0]["pre_close"] == None:
            return ""
        pre_close = float(result[0]["pre_close"])
        rs_zf = round((close-pre_close)*100/pre_close,2)
        #queue = args["queue"]
        flow_money = round(float(codeinfo["flow_money"])/100000000,2)
        with open("H:/model/score.txt","a+") as f:
            f.write(codeinfo["code"]+"\t"+codeinfo["codename"]+"\t"+str(flow_money)+"\t"+str(score)+"\t"+str(money_score)+"\t"+str(zf)+"\t"+str(rs_zf)+"\n")
        """
        if score > 50 and score < 60 and zf > 0 and zf < 5:
            if codeinfo["industry"] in ["半导体","通信设备","通用设备","计算机设备","文化传媒","互联网金融","通信服务"
                                        "多元金融","酿酒行业","互联网服务","光学光电子","消费电子","电子元件","软件开发"
                                        "游戏",]:
                if flow_money > 30 and flow_money < 50:
                    queue.put([codeinfo["code"], codeinfo["codename"], codeinfo["industry"], flow_money, score, zf])
        """






